
#ifndef __WND__
#define __WND__

typedef	unsigned char CLASS;

#define	CI_NULL		0
#define	CI_LABEL	1
#define	CI_EDIT		2
#define	CI_LIST		3

#define	MAX_MENU	128		//菜单最大项

//菜单项结构
typedef struct tagMenuItem {
    int	 cls;			// 菜单项类
    int	 x;			    // 项显示位置
    int	 y;
    char *labelText;	// EDIT或LIST标题或菜单项
    int editLen;		// 编辑长度

    char *editText;	    // 编辑显示字符
    char *editTemp;	    // 编辑显示临时字符
    char **listTable;   // 显示列表项
    int	*listCnt;		// 列表项计数
    int	*listCntTemp;	// 显示用计数
    int	listMax;		// 最大项计数
    int	subx;			// EDIT或LIST显示起始位置
    int	suby;
    int	tabStop;		//焦点停靠,1-当前有焦点,0-当前无焦点
    int	cmd;			//命令
    struct	tagMenu	*child;	//子菜单
} ITEM;

//菜单结构
typedef struct	tagMenu {
    char *title;			    //标题
    int	size;			    //菜单项计数
    int tab;
    ITEM	*items;			    //菜单项指针
    struct	tagMenu	*parent;	//上一级菜单
} MENU;

#define	MAX(a, b)	((a) > (b) ? (a) : (b))

#define	MENU_NULL	(MENU*)0

#define	LABEL(x, y, labelText, cmd, sub) \
	{CI_LABEL, x, y, labelText, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, cmd, sub},

#define	LIST(x, y, title, listTable, listCnt, listCntTemp, listMax, listx, listy, cmd, sub) \
	{CI_LIST, x, y, title, 0, 0, 0, listTable, listCnt, listCntTemp, listMax, listx, listy, 0, cmd, sub},

#define	EDIT(x, y, title, editx, edity, editLen, editText, editTemp, cmd, sub) \
	{CI_EDIT, x, y, title, editLen, editText, editTemp, 0, 0, 0, 0, editx, edity, 0, cmd,sub},

#define SUBMENU(name) \
	ITEM Item_##name[]={

#define ENDMENU(name,title,tab,parent) \
}; \
MENU name = {title, sizeof(Item_##name)/sizeof(ITEM), tab, Item_##name, parent};

//菜单项命令映射
typedef	void	(*CMDPROC)(int dwParam, char *pbName);
typedef	struct	tagCMDMAP {
    char	cmd;
    CMDPROC	pf;
    char   *pbName;
} CMDMAP;

#define	ON_COMMAND(cmd,func,name) \
	{cmd, (CMDPROC)func, name},

#define	BEGIN_COMMAND_MAP() \
	const	CMDMAP	CommandEntries[] = \
	{ \

#define	END_COMMAND_MAP() \
	{0, (CMDPROC)0, (char*)0} \
	}; \
	const CMDMAP *GetCommandMap() \
		{return CommandEntries;}

//窗口重刷命令
#define	REDRAW_ALL		        0		//全部重画
#define	REDRAW_NO		        1		//不重画
#define	REDRAW_ITEM		        2		//重画某一项

#define	CMD_NULL		        0		//空命令
#define CMD_DEFAULT         	1       //默认的执行命令，只打印，不作其它操作
#define CMD_MEMORY_TEST     	2
#define CMD_UART_CONNECT    	3
#define CMD_SYSTEM_SET      	4


//窗口处理函数
extern	void DefWndProc(void);
extern	int OnCmdMessage(int cmd);
extern  MENU *curWnd;				//当前显示窗口

extern void CmdDefaultProcess(int dwParam, char *pbName);
extern void SpinValue(int *value, int min, int max, int dir);

#endif	/* end of __WND__ */
